package com.ruoyi.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.domain.DangerGoodsPur;
import com.ruoyi.business.mapper.DangerGoodsPurMapper;
import com.ruoyi.business.service.IDangerGoodsPurService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 危险品采购记录Service业务层处理
 * 
 * @author qiancheng
 * @date 2025-06-13
 */
@Service
public class DangerGoodsPurServiceImpl extends ServiceImpl<DangerGoodsPurMapper, DangerGoodsPur> implements IDangerGoodsPurService
{
    @Autowired
    private DangerGoodsPurMapper dangerGoodsPurMapper;

    /**
     * 查询危险品采购记录
     * 
     * @param id 危险品采购记录主键
     * @return 危险品采购记录
     */
    @Override
    public DangerGoodsPur selectDangerGoodsPurById(Long id)
    {
        return dangerGoodsPurMapper.selectDangerGoodsPurById(id);
    }

    /**
     * 安全管理->>危险品管理->>查询危险品采购记录列表
     * 
     * @param dangerGoodsPur 危险品采购记录
     * @return 危险品采购记录
     */
    @Override
    public List<DangerGoodsPur> selectDangerGoodsPurList(DangerGoodsPur dangerGoodsPur)
    {
        return dangerGoodsPurMapper.selectDangerGoodsPurList(dangerGoodsPur);
    }

    /**
     * 安全管理->>危险品管理->>新增危险品采购记录
     * 
     * @param dangerGoodsPur 危险品采购记录
     * @return 结果
     */
    @Override
    public int insertDangerGoodsPur(DangerGoodsPur dangerGoodsPur)
    {
        // 设置创建时间
        dangerGoodsPur.setCreateTime(DateUtils.getNowDate());
        // 设置默认删除标记：0-正常，1-删除
        if (dangerGoodsPur.getDelFlag() == null || dangerGoodsPur.getDelFlag().trim().isEmpty()) {
            dangerGoodsPur.setDelFlag("0");
        } else {
            // 限制delFlag的值，只允许"0"或"1"
            String delFlag = dangerGoodsPur.getDelFlag().trim();
            if (!"0".equals(delFlag) && !"1".equals(delFlag)) {
                dangerGoodsPur.setDelFlag("0");
            }
        }
        return dangerGoodsPurMapper.insert(dangerGoodsPur);
    }

    /**
     * 安全管理->>危险品管理->>修改危险品采购记录
     * 
     * @param dangerGoodsPur 危险品采购记录
     * @return 结果
     */
    @Override
    public int updateDangerGoodsPur(DangerGoodsPur dangerGoodsPur)
    {
        // 设置更新时间
        dangerGoodsPur.setUpdateTime(DateUtils.getNowDate());
        // 验证并修正delFlag的值
        if (dangerGoodsPur.getDelFlag() != null && !dangerGoodsPur.getDelFlag().trim().isEmpty()) {
            String delFlag = dangerGoodsPur.getDelFlag().trim();
            if (!"0".equals(delFlag) && !"1".equals(delFlag)) {
                dangerGoodsPur.setDelFlag("0");
            }
        }
        return dangerGoodsPurMapper.updateDangerGoodsPur(dangerGoodsPur);
    }

    /**
     * 安全管理->>危险品管理->>批量删除危险品采购记录
     * 
     * @param ids 需要删除的危险品采购记录主键
     * @return 结果
     */
    @Override
    public int deleteDangerGoodsPurByIds(Long[] ids)
    {
        return dangerGoodsPurMapper.deleteDangerGoodsPurByIds(ids);
    }

    /**
     * 删除危险品采购记录信息
     * 
     * @param id 危险品采购记录主键
     * @return 结果
     */
    @Override
    public int deleteDangerGoodsPurById(Long id)
    {
        return dangerGoodsPurMapper.deleteDangerGoodsPurById(id);
    }
}
